package cn.fl.mcr.service.impl;

import cn.cmm.base.framework.exception.BaseException;
import cn.fl.mcr.service.IMcrBillMReService;
import cn.fl.mcr.transform.McrBillMReVOTransform;
import cn.fl.mcr.transform.McrBillMVOTransform;
import cn.fl.mcr.vo.McrBillMReVO;
import cn.fl.mcr.vo.McrBillMVO;
import cn.lionbridgecapital.loan.model.base.Pager;
import cn.lionbridgecapital.loan.model.condition.McrInformTransferQC;
import cn.lionbridgecapital.loan.model.dto.McrBillMReDTO;
import cn.lionbridgecapital.loan.model.dto.McrInformTransferDTO;
import cn.lionbridgecapital.loan.model.utils.CollectionUtils;
import cn.lionbridgecapital.loan.service.api.IMcrBillMReApiService;
import cn.lionbridgecapital.loan.service.api.IMcrInformTransferApiService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description: 回购账单主表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class McrBillMReServiceImpl implements IMcrBillMReService {

    private static final Logger logger = LoggerFactory.getLogger(McrBillMReServiceImpl.class);

    @Autowired
    private IMcrBillMReApiService mcrBillMReApiService;

    @Override
    public Pager searchListPage(Pager page) throws BaseException {
        page = this.mcrBillMReApiService.searchMcrBillMListConditionPage(page);
        logger.info("调用dubbo服务，返回的信息：{}", JSON.toJSONString(page));
        if (CollectionUtils.isEmpty(page.getResultList())) {
            return page;
        }
        convertToVo(page);
        return page;
    }

    @Override
    public McrBillMReVO selectById(Long id) {
        McrBillMReDTO dto = mcrBillMReApiService.selectById(id);
        logger.info("调用远程接口，selectById : 返回的信息：{}" , dto.toString() );
        McrBillMReVO vo = McrBillMReVOTransform.toVO(dto);
        return vo;
    }

    /**
     * 转换为Vo 页面显示
     * @param page
     */
    private void convertToVo(Pager page) {
        List<Map<String,Object>> resultList = (List<Map<String,Object>>) page.getResultList();
        List<McrBillMReVO> mcrBillMreVos = new ArrayList<>(page.getEveryPage());
        McrBillMReVO vo;
        for (Map<String, Object> objMap : resultList) {
            vo = JSONObject.parseObject(JSON.toJSONString(objMap), McrBillMReVO.class);
            mcrBillMreVos.add(vo);
        }
        page.setResultList(mcrBillMreVos);
    }




}
